<template>
  <div class="consumption-chart">
    <div class="consumption-summary">
      <div class="summary-item">
        <div class="summary-label">人均消费</div>
        <div class="summary-value">¥{{ data.average }}</div>
      </div>
      <div class="summary-item">
        <div class="summary-label">总消费额</div>
        <div class="summary-value">¥{{ formatNumber(data.total) }}</div>
      </div>
    </div>
    
    <div class="consumption-breakdown">
      <div 
        v-for="item in data.categories" 
        :key="item.name"
        class="category-item"
      >
        <div class="category-header">
          <span class="category-name">{{ item.name }}</span>
          <span class="category-percent">{{ item.value }}%</span>
        </div>
        <div class="category-progress">
          <div 
            class="progress-fill" 
            :style="{ 
              width: item.value + '%',
              backgroundColor: getCategoryColor(item.name)
            }"
          ></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  data: {
    type: Object,
    default: () => ({
      average: 0,
      total: 0,
      categories: []
    })
  }
})

const formatNumber = (num) => {
  return (num / 1000).toFixed(1) + 'k'
}

const getCategoryColor = (name) => {
  const colors = {
    '餐饮': '#00ff88',
    '住宿': '#00bcd4', 
    '门票': '#ffab40',
    '购物': '#66bb6a'
  }
  return colors[name] || '#00ff88'
}
</script>

<style scoped>
.consumption-chart {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.consumption-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.summary-item {
  text-align: center;
  padding: 0.8rem;
  background: rgba(0, 255, 136, 0.08);
  border: 1px solid rgba(0, 255, 136, 0.2);
  border-radius: 8px;
  transition: all 0.3s ease;
}

.summary-item:hover {
  background: rgba(0, 255, 136, 0.15);
  transform: translateY(-2px);
}

.summary-label {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 0.3rem;
}

.summary-value {
  font-size: 1.1rem;
  font-weight: bold;
  color: #00ff88;
  text-shadow: 0 0 10px rgba(0, 255, 136, 0.5);
}

.consumption-breakdown {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.category-item {
  background: rgba(0, 255, 136, 0.06);
  border: 1px solid rgba(0, 255, 136, 0.15);
  border-radius: 8px;
  padding: 0.8rem;
  transition: all 0.3s ease;
}

.category-item:hover {
  background: rgba(0, 255, 136, 0.12);
  border-color: rgba(0, 255, 136, 0.3);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.category-name {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
}

.category-percent {
  font-size: 0.85rem;
  font-weight: 600;
  color: #00ff88;
  text-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
}

.category-progress {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: all 0.3s ease;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
</style> 